<template>
  <div>
    <el-form :model="formItem" label-width="100px" size="mini" class="form-view">
      <el-form-item label="类别名称：">
        {{ formItem.text }}
      </el-form-item>
      <el-form-item label="类别编码：">
        {{ formItem.type }}
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {
  detail
} from '@neu/dcom-ui/api/dictionaryType'

// 定义一个表单原始项
const formItem = {
  type: '',
  text: ''
}
export default {
  name: 'DictionaryDescViewForm',
  props: {
    // 根据id可判断是新建还是更新
    id: {
      required: false,
      type: Number,
      default: -1
    }
  },
  data() {
    return {
      // 查看的表单内容
      formItem: {
        ...formItem
      }
    }
  },
  watch: {
    // 监控id的变化，初始化表单数据
    id: function() {
      this.fetch()
    }
  },
  created() {
    this.fetch()
  },
  methods: {
    // 初始化表单数据
    fetch() {
      if (this.id !== -1) {
        detail(this.id).then(response => {
          this.formItem = {
            ...response.data
          }
        })
      } else {
        this.formItem = {
          ...formItem
        }
      }
    }
  }
}
</script>
